package com.sky.controller.admin;

import com.sky.constant.StatusConstant;
import com.sky.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/admin/shop")
public class ShopController {
    @Autowired
    RedisTemplate redisTemplate;

    @PutMapping("/{status}")
    public Result setShopStatus(@PathVariable Integer status) {
        //设置店铺状态(修改redis中的店铺状态)
        redisTemplate.opsForValue().set(StatusConstant.SHOP_STATUS, status);
        //封装出来结果
        return Result.success();
    }

    @GetMapping("status")
    public Result getShopStatus() {
        //获取店铺状态 (从redis中获取店铺状态)
        Integer shopStatus = (Integer) redisTemplate.opsForValue().get(StatusConstant.SHOP_STATUS);
        //封装处理结果
        return Result.success(shopStatus);
    }
}
